<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="预约管理">
    <meta name="keywords" content="预约列表">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">

    <style>
        .avatar-uploader .el-upload {
            border: 1px dashed #d9d9d9;
            border-radius: 6px;
            cursor: pointer;
            position: relative;
            overflow: hidden;
        }
        .avatar-uploader .el-upload:hover {
            border-color: #409EFF;
        }
        .avatar-uploader-icon {
            font-size: 28px;
            color: #8c939d;
            width: 178px;
            height: 178px;
            line-height: 178px;
            text-align: center;
        }
        .avatar {
            width: 178px;
            height: 178px;
            display: block;
        }
        .datatable {
            position: relative;
            box-sizing: border-box;
            -webkit-box-flex: 1;
            width: 100%;
            max-width: 100%;
            font-size: 14px;
            color: rgb(96, 98, 102);
            overflow: hidden;
            flex: 1 1 0%;
        }
        .datatable td, .datatable th {
            padding: 12px 0;
            min-width: 0;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            text-overflow: ellipsis;
            vertical-align: middle;
            position: relative;
            text-align: left;
        }
        .el-input__inner{
            width: 180px;
        }
    </style>
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>检查项管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>预约列表</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <div class="box">
            <div class="filter-container">
                <template>
                    <div class="block">
                        <el-date-picker v-model="time"
                                        type="daterange"
                                        align="right"
                                        unlink-panels
                                        range-separator="至"
                                        start-placeholder="开始日期"
                                        end-placeholder="结束日期">
                        </el-date-picker>

                        <el-select v-model="orderType" placeholder="预约类型">
                            <el-option :value="'微信预约'">
                                微信预约
                            </el-option>
                            <el-option :value="'电话预约'" >
                                电话预约
                            </el-option>
                        </el-select>

                        <el-select v-model="orderStatus" placeholder="预约状态">
                            <el-option :value="'未到诊'" >
                                未到诊
                            </el-option>
                            <el-option :value="'已到诊'">
                                已到诊
                            </el-option>
                        </el-select>

                        <el-input placeholder="姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button @click="pagination.currentPage=1;findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                </template>


            </div>
            <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                <el-table-column type="index" align="center" label="序号"></el-table-column>
                <el-table-column prop="orderDate" label="预约日期" align="center"></el-table-column>
                <!--<el-table-column prop="orderAddress" label="预约地址" align="center"></el-table-column>-->
                <el-table-column prop="mname" label="姓名" align="center"></el-table-column>
                <el-table-column prop="phoneNumber" label="手机号" align="center"></el-table-column>
                <el-table-column prop="orderType" label="预约类型" align="center"></el-table-column>
                <el-table-column prop="sname" label="套餐名称" align="center"></el-table-column>
                <el-table-column prop="orderStatus" label="预约状态" align="center">
                    <template slot-scope="scope">
                        <span>{{scope.row.orderStatus}}</span>
                        <el-switch
                                v-model="scope.row.orderStatus"
                                active-color="#13ce66"
                                inactive-color="#ff4949"
                                active-value="未到诊"
                                inactive-value="已到诊"
                                @change="changeStatus(scope.row)">
                        </el-switch>
                    </template>
                </el-table-column>
                <el-table-column label="预约操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                        <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-container">
                <el-pagination
                        class="pagiantion"
                        @current-change="handleCurrentChange"
                        :current-page="pagination.currentPage"
                        :page-size="pagination.pageSize"
                        layout="total, prev, pager, next, jumper"
                        :total="pagination.total">
                </el-pagination>
            </div>

            <div class="add-form">
                <el-dialog title="新增预约" :visible.sync="dialogFormVisible">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.name"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>适用人群</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">
                                                {{ c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}
                                            </label></td>

                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible = false">取消</el-button>
                        <el-button type="primary" @click="handleAdd()">确定</el-button>
                    </div>
                </el-dialog>
            </div>

            <div class="add-form">
                <el-dialog title="编辑预约" :visible.sync="dialogFormVisible4Edit">
                    <template>
                        <el-tabs v-model="activeName" type="card">
                            <el-tab-pane label="基本信息" name="first">
                                <el-form label-position="right" label-width="100px">
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="姓名">
                                                <el-input v-model="formData.mname"/>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="身份证号">
                                                <el-input v-model="formData.idCard"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="出生日期">
                                                <el-date-picker
                                                        v-model="formData.birthday"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="手机号">
                                                <el-input v-model="formData.phoneNumber"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="性别">
                                                <el-select v-model="formData.sex">
                                                    <el-option label="男" value="1"></el-option>
                                                    <el-option label="女" value="2"></el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="12">
                                            <el-form-item label="年龄">
                                                <el-input v-model="formData.age"/>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>

                                    <el-row>
                                        <el-col :span="12">
                                            <el-form-item label="预约时间">
                                                <el-date-picker
                                                        v-model="formData.orderDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-form>
                            </el-tab-pane>
                            <el-tab-pane label="套餐信息" name="second">
                                <div class="checkScrol">
                                    <table class="datatable">
                                        <thead>
                                        <tr>
                                            <th>选择</th>
                                            <th>套餐名称</th>
                                            <th>适用人群</th>
                                            <th>套餐介绍</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <tr v-for="c in tableData">
                                            <td>
                                                <input :id="c.id" v-model="setmealIds" type="checkbox" :value="c.id">
                                            </td>
                                            <td><label :for="c.id">{{c.name}}</label></td>
                                            <td><label :for="c.id">
                                                {{ c.sex == '0' ? '不限' : c.sex == '1' ? '男' : '女'}}
                                            </label></td>

                                            <td><label :for="c.id">{{c.remark}}</label></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </el-tab-pane>
                        </el-tabs>
                    </template>
                    <div slot="footer" class="dialog-footer">
                        <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                        <el-button type="primary" @click="handleEdit()">确定</el-button>
                    </div>
                </el-dialog>
            </div>
        </div>
    </div>
</div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            activeName:'first',//添加/编辑窗口Tab标签名称
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null//查询条件
            },
            time:"",
            orderType:"",
            orderStatus:"",
            dataList: [],//当前页要展示的分页列表数据
            formData: {},//表单数据
            tableData:[],//添加表单窗口中套餐数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            setmealIds:[],//添加表单窗口中套餐复选框对应id
            rules: {//校验规则
                /*code: [{ required: true, message: '项目编码为必填项', trigger: 'blur' }],
                name: [{ required: true, message: '项目名称为必填项', trigger: 'blur' }]*/
            }
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
            this.findPage();
        },
        methods: {
            //编辑
            handleEdit() {
                axios.post("/orderlist/edit?setmealIds="+this.setmealIds,this.formData).then((res) => {
                    if(res.data.flag){
                        //执行成功，关闭编辑窗口
                        this.dialogFormVisible4Edit = false;
                        //弹出提示信息
                        this.$message({
                            type:'success',
                            message:res.data.message
                        });
                        //分页查询
                        this.findPage();
                    }else{
                        //执行失败，弹出提示信息
                        this.$message.error(res.data.message);
                    }
                });
            },
            showMessage(r){
                if(r == 'Error: Request failed with status code 403'){
                    //权限不足
                    this.$message.error('无访问权限');
                    return;
                }else{
                    this.$message.error('未知错误');
                    return;
                }
            },
            //添加
            handleAdd () {

                //发送异步请求 ,完成数据添加  传会员信息和预约的套餐信息
                axios.post("/orderlist/add?setmealId=" + this.setmealIds[0], this.formData).then(response => {
                    //添加成功
                    if (response.data.flag) {
                        //隐藏弹出框
                        this.dialogFormVisible = false;
                        //展示提示信息
                        this.$message.success(response.data.message);
                        this.findPage();
                        return;
                    }
                    //添加失败
                    this.$message.error(response.data.message);
                })

            },
            //分页查询
            findPage() {
                var param={
                    //当前页码
                    currentPage: this.pagination.currentPage,
                    //显示数量
                    pageSize: this.pagination.pageSize,
                    //查询字段
                    queryString: this.pagination.queryString
                }

                axios.post("/orderlist/findPage",param).then((res)=>{
                    this.pagination.total=res.data.total;
                    this.dataList=res.data.data.rows;
                });
            },
            // 重置表单
            resetForm() {
                this.formData={};
                this.activeName = 'first';
                this.setmealIds=[];
            },
            // 弹出添加窗口
            handleCreate() {
                //默认展示第一页
                this.activeName = "first";
                //展示弹出框
                this.dialogFormVisible = true;
                //重置表单数据
                this.resetForm();
                //发送异步请求获取套餐数据
                axios.get("/orderlist/findAll")
                    .then(res => {
                        if (res.data.flag) {
                            this.tableData = res.data.data;
                            return;
                        }
                        this.$message.error(res.data.message);
                    })
            },

            //切换页码
            handleCurrentChange(currentPage) {
                this.pagination.currentPage=currentPage;
                this.findPage();
            },
            handleUpdate(row) {
                //显示编辑弹出框
                this.dialogFormVisible4Edit = true;
                //重置编辑弹出框数据
                this.resetForm();
                //默认选中第一个选项卡
                this.activeName = "first";
                //查询预约信息
                axios.get("/orderlist/findById?id=" + row.id).then(response => {
                    if (!response.data.flag) {
                        this.$message.error(response.data.message);
                        return;
                    }
                    this.formData = response.data.data;
                    this.setmealId[0] = response.data.data.setmeal.id;
                    this.inputIdCardInEdit(this.formData.member.idCard);
                });
                //发送异步请求获取套餐数据
                axios.get("/orderlist/findAll")
                    .then(res => {
                        if (res.data.flag) {
                            this.tableData = res.data.data;
                            return;
                        }
                        this.$message.error(res.data.message);
                    })
            },
            changeStatus(row) {
                //触发修改动作，传入的是修改后的状态
                axios.put("/orderlist/changeStatus", {id: row.id, orderStatus: row.orderStatus})
                    .then((res) => {
                        if (res.data.flag) {
                            this.$message.success(res.data.message);
                            this.dialogFormVisibleEdit = false;
                            this.resetForm();
                        }
                        else {
                            this.$message.error(res.data.message);
                            //修改失败
                            row.orderStatus = row.orderStatus.equals('已到诊') ? '未到诊' : '已到诊';
                        }
                    })
            },
            // 删除
            handleDelete(row) {
                this.$confirm("数据删除后将无法回复，请确认是否删除?","提示",{
                    type: 'warning'
                }).then(()=>{
                    axios.delete("/orderlist/delete?id="+row.id).then((res)=>{
                        if(res.data.flag){
                            //执行成功
                            //弹出成功提示信息
                            this.$message({
                                type:'success',
                                message:res.data.message
                            });
                            //重新进行分页查询
                            this.findPage();
                        }else{
                            //执行失败
                            this.$message.error(res.data.message);
                        }
                    }).catch((r)=>{
                        if(r == 'Error: Request failed with status code 403'){
                            //权限不足
                            this.$message.error('无访问权限');
                            return;
                        }else{
                            this.$message.error('未知错误');
                            return;
                        }
                    });
                }).catch(()=>{
                    this.$message({
                        type:'info',
                        message:'操作已取消'
                    })
                });
            }
        }
    })
</script>
</html>